const Express = require("express");
const UserSymptomSubServer = require("../../servers/UserSymptomSub");
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();

/**
 * 获取所有检查分类
 */
router.get("/getAllUserSymptomSub/:id", async (req, res) => {
  try {
    const id = req.params.id;
    const result = await UserSymptomSubServer.getAll(id);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 批量添加检查分类
 */
router.post("/bulkCreateUserSymptomSub", async (req, res) => {
  try {
    const result = await UserSymptomSubServer.bulkCreate(req.body);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 批量添加检查分类与症状
 */
router.post("/bulkCreateUserSymptomSubAndSym", async (req, res) => {
  try {
    const result = await UserSymptomSubServer.bulkCreateSym(req.body);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 添加检查分类
 */
router.post("/addUserSymptomSub", async (req, res) => {
  try {
    const result = await UserSymptomSubServer.add(req.body);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 更新检查分类
 */
router.post("/updateUserSymptomSub/:id", async (req, res) => {
  try {
    const id = req.params.id;
    const result = await UserSymptomSubServer.update(id);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 根据id获取检查分类
 */
router.post("/getUserSymptomSub/:id", async (req, res) => {
  try {
    const id = req.params.id;
    const result = await UserSymptomSubServer.getById(id);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 根据id删除检查分类
 */
router.post("/delUserSymptomSub/:id", async (req, res) => {
  try {
    const id = req.params.id;
    const result = await UserSymptomSubServer.delete(id);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

module.exports = router;
